<template>
	<view>
		<view class="head-tips">
			<text>温馨提示：早上9点至下午18点提现两小时到账,18点后提现次日9点后到账</text>
		</view>

		<!-- 1，提现标题 -->
		<view class="title">
			<text>提现金额</text>
		</view>
		<!-- 2，输入金额 -->
		<view class="price">
			<text>￥</text>
			<input v-model="price" type="number" />
		</view>
		<!-- 3，提示 -->
		<view class="tips" v-if="balance >= 10">
			<text class="left">当前零钱余额{{balance}}元，</text>
			<text class="right" @click="allTx">全部提现</text>
		</view>
		<view class="tips" v-else>
			<text class="left">当前零钱余额{{balance}}元，低于10元无法提现</text>
		</view>
		<!-- 4，按钮 -->
		<view class="btn" @click="clickFun">
			<text>提现</text>
		</view>

		<!-- 密码框 -->
		<pay-pop txt="支付密码" :pwdlength="6" ref="pay_pop" @pwd_e="pwdSend"></pay-pop>
	</view>
</template>

<script>
	import payPop from '@/components/apk/pay-pop/pay-pop.vue'

	import {
		queryBalance,
		cashWithdrawal
	} from '@/api/http/main/my/pay.js'

	export default {
		components: {
			payPop
		},
		data() {
			return {
				price: '',
				balance: '0'
			}
		},
		methods: {
			//查询余额
			queryBalance() {
				var that = this
				queryBalance().then(res => {
					if (res.data.pubInfo.code !== 0) {
						return uni.$showMsg(res.data.pubInfo.message);
					}
					that.balance = res.data.busInfo
				})
			},
			//点击提现
			clickFun() {
				if (this.price == '' || this.price <= 0) {
					return uni.$showMsg('请输入提现金额');
				}

				if (parseFloat(this.price) < 10) {
					return uni.$showMsg('无法提取10元以下金额');
				}

				if (parseFloat(this.price) > 1000) {
					return uni.$showMsg('一次最多只能提出1000');
				}

				//this.showTitle()
				this.$refs.pay_pop.Open()

			},
			pwdSend(e) {
				var that = this
				cashWithdrawal(parseFloat(this.price), e).then(res => {
					if (res.data.pubInfo.code !== 0) {
						return uni.$showMsg(res.data.pubInfo.message);
					}
					//刷新数据
					//that.queryBalance()

					uni.$showMsg(res.data.busInfo)

					setTimeout(function() {
						uni.redirectTo({
							url: '/subpkg/main/my/assets/assets/assets'
						})
					}, 800)

					return;
				})
			},
			allTx() {
				if (this.balance == 0 || this.balance == '0') {
					return uni.$showMsg('您没有多余金额提现');
				}
				if (parseFloat(this.price) < 10) {
					return uni.$showMsg('无法提取10元以下金额');
				}

				if (parseFloat(this.price) > 10000) {
					return uni.$showMsg('一次最多只能提出10000');
				}
				this.price = this.balance

				//this.showTitle()
				//输入密码
				this.$refs.pay_pop.Open()
			},

			async showTitle(item) {
				//手续费计算
				var sxf = (parseFloat(this.price) * 0.01) + 1
				var sxfP = Math.floor(sxf * 100) / 100

				var that = this
				uni.$isShowModal('您的提现需要扣扣除' + sxfP + '元手续费').then(resultState => {
					if (resultState) {
						//输入密码
						that.$refs.pay_pop.Open()
					}
				})
			}

		},
		onLoad() {
			this.queryBalance()
		},
		//跳转设置页面
		onNavigationBarButtonTap(e) {
			//console.log(e)
			// return uni.navigateTo({
			// 	url: '/subpkg/msg/set/set-user/set-user?msgObject=' + JSON.stringify(this.msgObjectData)
			// })
			return uni.navigateTo({
				url: '/subpkg/main/my/assets/assets-record/assets-record'
			})

		}
	}
</script>

<style lang="scss" scoped>
	.head-tips {
		// width: 100%;
		background-color: #FBEBC4;
		padding: 15rpx;
		text-align: center;

		text {
			font-size: 22rpx;
		}
	}

	.title {
		height: 100rpx;
		line-height: 100rpx;
		font-size: 32rpx;
		width: 100%;

		text {
			margin-left: 4%;
		}
	}

	.price {
		line-height: 100rpx;
		font-size: 32rpx;
		height: 100rpx;
		display: flex;
		width: 100%;

		text {
			margin-left: 4%;
		}

		input {
			width: 80%;
			height: 60rpx;
			margin-top: 20rpx;
			border-bottom: 1rpx solid rgba(204, 204, 204, 1);
		}
	}

	.tips {
		width: 100%;
		font-size: 32rpx;
		height: 100rpx;
		line-height: 100rpx;

		.left {
			margin-left: 4%;
		}

		.right {
			color: rgba(42, 130, 228, 1);
		}

		// display: flex;
	}

	.btn {
		margin-top: 50rpx;
		width: 90%;
		height: 100rpx;
		font-size: 34rpx;
		line-height: 100rpx;
		text-align: center;
		color: #fff;
		background-color: #43CF7C;
		margin-left: 5%;
		border-radius: 50rpx;
	}
</style>